﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.Utility;
using YouHP.BLL;

namespace YouHP.Pages.TreatmentHistory
{
    public class TreatmentShowAjax:BasePage
    {
        protected List<TreatmentInfo> TreatmentList = new List<TreatmentInfo>();
        protected int pageIndex = 1;
        protected int TreatmentCount = 0;
        protected int pageCount;
        protected override void ShowPage()
        {
            base.ShowPage();

            TreatmentSearchCondition cond = new TreatmentSearchCondition();
            cond.DiseaseId = RequestTools.GetQueryInt("diseaseId", 0);

            pageIndex = RequestTools.GetQueryInt("page", 1);

            TreatmentList = TreatmentBLL.Instance.GetTreatmentList(10, pageIndex, cond, out TreatmentCount);


            StringBuilder sb = new StringBuilder();
            sb.Append("<div style=\"padding-left:10px\"><ul>");
            foreach (TreatmentInfo info in TreatmentList)
            {
                sb.Append("<li>" + "<a "+"href=\"#\""+" onclick=\"sel("+info.Id+",");
                sb.Append("\'"+ info.Name+"\'");
                sb.Append(");\""+">" + info.Name + "</a></li>");


            }
            sb.Append("</ul></div>");
        
            pageCount = Utils.GetPageCount(TreatmentCount, 10);
         
            StringBuilder sb2 = new StringBuilder();

            sb2.Append("<div class=\"pageing\">共" + TreatmentCount + "种&nbsp;&nbsp;");
            if (pageIndex + 3 < pageCount)
            {

                for (int i = pageIndex; i <= pageIndex + 3; i++)
                {
                    sb2.Append("<a href=\"#\" onclick=\"getTreatmentList("+"\'"+cond.DiseaseId+"\'"+","+i+")\">" + i + "</a>");
                }
                int pageEnd = pageIndex + 4;
                sb2.Append("<a href=\"#\" onclick=\"getTreatmentList("+"\'"+cond.DiseaseId+"\'"+","+pageEnd+")\">" + "下一页" + "</a>");
            }
            else
            {
                for (int i = pageIndex; i <= pageCount; i++)
                {
                    sb2.Append("<a href=\"#\" onclick=\"getTreatmentList(" + "\'" + cond.DiseaseId + "\'" + "," +i+")\">" + i + "</a>");
                }

            }
            sb.Append(sb2);
            ResponseXML(sb);
    






        }

        private void ResponseXML(StringBuilder sb)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/html";
            System.Web.HttpContext.Current.Response.Expires = 0;


            System.Web.HttpContext.Current.Response.Write(sb.ToString());
            System.Web.HttpContext.Current.Response.End();
        }
    }
}
